﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Foundation
{
    /// <summary>
    /// 表示双数组实现的前缀搜索树
    /// </summary>
    public sealed class DartTree
    {
        /// <summary>
        /// 
        /// </summary>
        private int[] @base;

        /// <summary>
        /// 
        /// </summary>
        private int[] @check;

        private const int HasValue = 1;

        /// <summary>
        /// 
        /// </summary>
        private const int NoValue = -1;

        // Definition 1:
        //
        // check[base[s] + c] = s;
        // next[base[s]+c] = t;
        //
        // Definition 2:
        //
        // check[base[s] + c] = s;
        // base[s] + c = t;

        public void Append(string @string)
        {
            Append(@string);
        }

        public void Append(char[] array)
        {
            Append(array);
        }

        public void Append(IEnumerable<char> iterator)
        {
            int s = 0;
            int t = 0;
            foreach(var c in iterator) {
                t = @base[s] + c;
                @base[t] = @base[@base[s] + c];
            }
        }
    }
}
